import React from 'react';
import {Tag, Tooltip} from 'antd';
import {message, Upload} from 'antd';
import Counter from "../../mobx-store";
import {IMPORT_MARKDOWN_URL} from "./api";


interface MDUploadCProps {

    onClose: () => void;
}

const MDUpload: React.FC<MDUploadCProps> = (uploadCProps: MDUploadCProps) => {


    const onChange = (info: any) => {
        if (info.file.status === 'done') {
            message.success(`${info.file.name} file uploaded successfully`).then(r => console.log(r));
            Counter.setUrl(info.file.response)
            uploadCProps.onClose();
        }
    }
    return (
        <>
            <Upload
                multiple={true}
                name='file'
                action={IMPORT_MARKDOWN_URL}
                data={{path: Counter.path}}
                headers={{
                    authorization: 'authorization-text',
                }}
                onChange={onChange}>
                <Tooltip placement="right" title={"按住ctrl可多选，ctrlA全选"}>
                    <Tag color="blue">
                        导入
                    </Tag>
                </Tooltip>
            </Upload>
        </>
    )
}


export default MDUpload;
